#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int N, C;
const int MAXN = 2010;

int fa[MAXN];

struct node
{
    int x;
    int y;
} n[MAXN];

struct edge
{
    int from;
    int to;
    long long weight;
} e[MAXN * MAXN];

void init()
{
    for (int i = 1; i <= N; i++)
    {
        fa[i] = i;
    }
}

int find(int x)
{
    if (x == fa[x])
        return x;
    fa[x] = find(fa[x]);
    return fa[x];
}

void merge(int x, int y)
{
    int tx = find(x);
    int ty = find(y);
    if (tx != ty)
    {
        fa[tx] = ty;
    }
}

long long cost(const node &a, const node &b)
{
    return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}

bool cmp(const edge &A, const edge &B)
{
    return A.weight < B.weight;
}

int main()
{
    cin >> N >> C;
    for (int i = 1; i <= N; i++)
    {
        cin >> n[i].x >> n[i].y;
    }

    int cnt = 1;
    long long totalcost = 0;
    int num = 0;

    for (int i = 1; i <= N; i++)
    {
        for (int j = i + 1; j <= N; j++)
        {
            e[cnt].from = i;
            e[cnt].to = j;
            e[cnt].weight = cost(n[i], n[j]);
            cnt++;
        }
    } //生成路径以及权值

    sort(e + 1, e + cnt, cmp); //按权值排序
    init();

    for (int i = 1; i < cnt; i++)
    {
        if (find(e[i].to) != find(e[i].from) && e[i].weight >= C)
        {
            merge(e[i].to, e[i].from); //合并
            num++;
            totalcost += e[i].weight;
        }
        if (num == N - 1)
        {
            cout << totalcost << endl;
            system("pause");
            return 0;
        }
    }
    cout << -1 << endl;
    system("pause");
    return 0;
}
